package base;

import java.util.concurrent.*;

/**
 * @AUTHOR LYF
 * @DATE 2022/2/14
 * @VERSION 1.0
 * @DESC
 * 创建线程的方式：
 * 1. 继承Thread
 * 2. 实现runnable
 * 3. 实现callable
 * 4. 线程池实现
 */
class ThreadTask extends Thread{
    @Override
    public void run() {
        System.out.println("hello! i am thread-task");
    }
}
class RunnableTask implements Runnable{
    @Override
    public void run() {
        System.out.println("hello! i am runnable-task");
    }
}
class CallableTask implements Callable{
    @Override
    public Object call() throws Exception {
        System.out.println("hello! i am Callable-task");
        return 1;
    }
}
public class CreateThread {
    public static void main(String[] args) {
        ThreadTask threadTask = new ThreadTask();
        threadTask.start();
        new Thread(new RunnableTask()).start();
        //new Thread(new CallableTask()).start();
        // FutureTask<Object> futureTask =
        //Executors.
//        Future<Integer> future = new FutureTask<>(new CallableTask());
//
//        while (future.isDone())
//        {
//            try {
//                System.out.println(future.get());
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            } catch (ExecutionException e) {
//                e.printStackTrace();
//            }
//        }

        FutureTask<Integer> futureTask = new FutureTask<Integer>(()->{
            return 1;
        });
        // FutureTask 实现 RunnableFuture (继承，Runnable和Future接口）
        new Thread(futureTask).start();// Thread 实现Runnable Runnable,
        new Thread(new FutureTask<Integer>(()->{return 0;}));
        //new Thread(new Future<Integer>(()->{return 0;}));

        ThreadGroup threadGroup1 = new ThreadGroup("group-1");
        //线程组的作用是，可以批量的管理线程或线程组对象，有效对线程或线程组对象进行组织。

        new Thread(threadGroup1,new ThreadTask(),"thread-1");
        //threadGroup1.activeCount();
        //threadGroup1.interrupt();
        //threadGroup1.setMaxPriority(1);

    }
}
